package com.google.zxing.pdf417.detector;

import com.google.zxing.BinaryBitmap;
import com.google.zxing.DecodeHintType;
import com.google.zxing.NotFoundException;
import com.google.zxing.ResultPoint;
import com.google.zxing.common.BitMatrix;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public final class Detector
{
  private static final int BARCODE_MIN_HEIGHT = 10;
  private static final int[] INDEXES_START_PATTERN = { 0, 4, 1, 5 };
  private static final int[] INDEXES_STOP_PATTERN = { 6, 2, 7, 3 };
  private static final float MAX_AVG_VARIANCE = 0.42F;
  private static final float MAX_INDIVIDUAL_VARIANCE = 0.8F;
  private static final int MAX_PATTERN_DRIFT = 5;
  private static final int MAX_PIXEL_DRIFT = 3;
  private static final int ROW_STEP = 5;
  private static final int SKIPPED_ROW_COUNT_MAX = 25;
  private static final int[] START_PATTERN = { 8, 1, 1, 1, 1, 1, 1, 3 };
  private static final int[] STOP_PATTERN = { 7, 1, 1, 3, 1, 1, 1, 2, 1 };

  private static void copyToResult(ResultPoint[] paramArrayOfResultPoint1, ResultPoint[] paramArrayOfResultPoint2, int[] paramArrayOfInt)
  {
    for (int i = 0; i < paramArrayOfInt.length; i++)
      paramArrayOfResultPoint1[paramArrayOfInt[i]] = paramArrayOfResultPoint2[i];
  }

  public static PDF417DetectorResult detect(BinaryBitmap paramBinaryBitmap, Map<DecodeHintType, ?> paramMap, boolean paramBoolean)
    throws NotFoundException
  {
    BitMatrix localBitMatrix = paramBinaryBitmap.getBlackMatrix();
    List localList = detect(paramBoolean, localBitMatrix);
    if (localList.isEmpty())
    {
      localBitMatrix = localBitMatrix.clone();
      localBitMatrix.rotate180();
      localList = detect(paramBoolean, localBitMatrix);
    }
    return new PDF417DetectorResult(localBitMatrix, localList);
  }

  private static List<ResultPoint[]> detect(boolean paramBoolean, BitMatrix paramBitMatrix)
  {
    ArrayList localArrayList = new ArrayList();
    int i = 0;
    int j = 0;
    int k = 0;
    while (true)
    {
      ResultPoint[] arrayOfResultPoint1;
      if (i < paramBitMatrix.getHeight())
      {
        arrayOfResultPoint1 = findVertices(paramBitMatrix, i, j);
        if ((arrayOfResultPoint1[0] != null) || (arrayOfResultPoint1[3] != null))
          break label140;
        if (k != 0)
          break label54;
      }
      label54: 
      do
      {
        return localArrayList;
        Iterator localIterator = localArrayList.iterator();
        while (localIterator.hasNext())
        {
          ResultPoint[] arrayOfResultPoint2 = (ResultPoint[])localIterator.next();
          if (arrayOfResultPoint2[1] != null)
            i = (int)Math.max(i, arrayOfResultPoint2[1].getY());
          if (arrayOfResultPoint2[3] != null)
            i = Math.max(i, (int)arrayOfResultPoint2[3].getY());
        }
        i += 5;
        j = 0;
        k = 0;
        break;
        k = 1;
        localArrayList.add(arrayOfResultPoint1);
      }
      while (!paramBoolean);
      label140: if (arrayOfResultPoint1[2] != null)
      {
        j = (int)arrayOfResultPoint1[2].getX();
        i = (int)arrayOfResultPoint1[2].getY();
      }
      else
      {
        j = (int)arrayOfResultPoint1[4].getX();
        i = (int)arrayOfResultPoint1[4].getY();
      }
    }
  }

  private static int[] findGuardPattern(BitMatrix paramBitMatrix, int paramInt1, int paramInt2, int paramInt3, boolean paramBoolean, int[] paramArrayOfInt1, int[] paramArrayOfInt2)
  {
    Arrays.fill(paramArrayOfInt2, 0, paramArrayOfInt2.length, 0);
    int i = paramArrayOfInt1.length;
    boolean bool = paramBoolean;
    int j = paramInt1;
    int i1;
    for (int k = 0; (paramBitMatrix.get(j, paramInt2)) && (j > 0); k = i1)
    {
      i1 = k + 1;
      if (k >= 3)
        break;
      j--;
    }
    int m = j;
    int n = 0;
    while (m < paramInt3)
      if ((bool ^ paramBitMatrix.get(m, paramInt2)))
      {
        paramArrayOfInt2[n] = (1 + paramArrayOfInt2[n]);
        m++;
      }
      else
      {
        if (n == i - 1)
        {
          if (patternMatchVariance(paramArrayOfInt2, paramArrayOfInt1, 0.8F) < 0.42F)
            return new int[] { j, m };
          j += paramArrayOfInt2[0] + paramArrayOfInt2[1];
          System.arraycopy(paramArrayOfInt2, 2, paramArrayOfInt2, 0, i - 2);
          paramArrayOfInt2[(i - 2)] = 0;
          paramArrayOfInt2[(i - 1)] = 0;
          n--;
          label190: paramArrayOfInt2[n] = 1;
          if (bool)
            break label213;
        }
        label213: for (bool = true; ; bool = false)
        {
          break;
          n++;
          break label190;
        }
      }
    if ((n == i - 1) && (patternMatchVariance(paramArrayOfInt2, paramArrayOfInt1, 0.8F) < 0.42F))
    {
      int[] arrayOfInt = new int[2];
      arrayOfInt[0] = j;
      arrayOfInt[1] = (m - 1);
      return arrayOfInt;
    }
    return null;
  }

  private static ResultPoint[] findRowsWithPattern(BitMatrix paramBitMatrix, int paramInt1, int paramInt2, int paramInt3, int paramInt4, int[] paramArrayOfInt)
  {
    ResultPoint[] arrayOfResultPoint = new ResultPoint[4];
    int[] arrayOfInt1 = new int[paramArrayOfInt.length];
    int i = paramInt3;
    int j = 0;
    int k;
    Object localObject1;
    if (i < paramInt1)
    {
      Object localObject2 = findGuardPattern(paramBitMatrix, paramInt4, paramInt3, paramInt2, false, paramArrayOfInt, arrayOfInt1);
      if (localObject2 != null)
      {
        while (paramInt3 > 0)
        {
          paramInt3--;
          int[] arrayOfInt3 = findGuardPattern(paramBitMatrix, paramInt4, paramInt3, paramInt2, false, paramArrayOfInt, arrayOfInt1);
          if (arrayOfInt3 != null)
            localObject2 = arrayOfInt3;
          else
            paramInt3++;
        }
        arrayOfResultPoint[0] = new ResultPoint(localObject2[0], paramInt3);
        arrayOfResultPoint[1] = new ResultPoint(localObject2[1], paramInt3);
        j = 1;
      }
    }
    else
    {
      k = paramInt3 + 1;
      if (j == 0)
        break label297;
      n = 0;
      localObject1 = new int[2];
      localObject1[0] = ((int)arrayOfResultPoint[0].getX());
      localObject1[1] = ((int)arrayOfResultPoint[1].getX());
      label163: if (k >= paramInt1)
        break label250;
      int[] arrayOfInt2 = findGuardPattern(paramBitMatrix, localObject1[0], k, paramInt2, false, paramArrayOfInt, arrayOfInt1);
      if ((arrayOfInt2 == null) || (Math.abs(localObject1[0] - arrayOfInt2[0]) >= 5) || (Math.abs(localObject1[1] - arrayOfInt2[1]) >= 5))
        break label243;
      localObject1 = arrayOfInt2;
    }
    label297: for (int n = 0; ; n++)
    {
      k++;
      break label163;
      paramInt3 += 5;
      break;
      label243: if (n > 25)
      {
        label250: k -= n + 1;
        arrayOfResultPoint[2] = new ResultPoint(localObject1[0], k);
        arrayOfResultPoint[3] = new ResultPoint(localObject1[1], k);
        if (k - paramInt3 >= 10)
          break label335;
        for (int m = 0; m < arrayOfResultPoint.length; m++)
          arrayOfResultPoint[m] = null;
      }
    }
    label335: return arrayOfResultPoint;
  }

  private static ResultPoint[] findVertices(BitMatrix paramBitMatrix, int paramInt1, int paramInt2)
  {
    int i = paramBitMatrix.getHeight();
    int j = paramBitMatrix.getWidth();
    ResultPoint[] arrayOfResultPoint = new ResultPoint[8];
    int[] arrayOfInt1 = START_PATTERN;
    copyToResult(arrayOfResultPoint, findRowsWithPattern(paramBitMatrix, i, j, paramInt1, paramInt2, arrayOfInt1), INDEXES_START_PATTERN);
    if (arrayOfResultPoint[4] != null)
    {
      paramInt2 = (int)arrayOfResultPoint[4].getX();
      paramInt1 = (int)arrayOfResultPoint[4].getY();
    }
    int[] arrayOfInt2 = STOP_PATTERN;
    copyToResult(arrayOfResultPoint, findRowsWithPattern(paramBitMatrix, i, j, paramInt1, paramInt2, arrayOfInt2), INDEXES_STOP_PATTERN);
    return arrayOfResultPoint;
  }

  private static float patternMatchVariance(int[] paramArrayOfInt1, int[] paramArrayOfInt2, float paramFloat)
  {
    int i = paramArrayOfInt1.length;
    int j = 0;
    int k = 0;
    for (int m = 0; m < i; m++)
    {
      j += paramArrayOfInt1[m];
      k += paramArrayOfInt2[m];
    }
    if (j < k);
    float f3;
    label142: 
    while (true)
    {
      return (1.0F / 1.0F);
      float f1 = j / k;
      float f2 = paramFloat * f1;
      f3 = 0.0F;
      int n = 0;
      if (n >= i)
        break;
      int i1 = paramArrayOfInt1[n];
      float f4 = f1 * paramArrayOfInt2[n];
      if (i1 > f4);
      for (float f5 = i1 - f4; ; f5 = f4 - i1)
      {
        if (f5 > f2)
          break label142;
        f3 += f5;
        n++;
        break;
      }
    }
    return f3 / j;
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.google.zxing.pdf417.detector.Detector
 * JD-Core Version:    0.6.2
 */